package com.wef.system.service.impl;

import java.util.List;
import java.util.Set;

import com.gfa4j.exception.ValidateRuntimeException;
import com.gfa4j.hibernate.BaseObject;
import com.gfa4j.service.impl.BaseServiceImpl;
import com.wef.system.entity.ViewButton;
import com.wef.system.service.ViewButtonService;

public class ViewButtonServiceImpl extends BaseServiceImpl implements ViewButtonService {

	public ViewButton addViewButton(ViewButton viewButton){
		
		return (ViewButton) super.saveObject(viewButton);
	}

	public void deleteViewButton(ViewButton viewButton) {		
		super.deleteObject(viewButton);
		
	}

	public ViewButton saveOrUpdateViewButton(ViewButton viewButton){	
		if (viewButton.getRowStatus() == BaseObject.ROWSTATUS_ADDED) {
			return this.addViewButton(viewButton);
		}
		if (viewButton.getRowStatus() == BaseObject.ROWSTATUS_MODIFIED) {
			return this.updateViewButton(viewButton);
		}
		if (viewButton.getRowStatus() == BaseObject.ROWSTATUS_DELETED) {
			this.deleteViewButton(viewButton);
			return null ;
		}
		return viewButton;
	}

	public Set<ViewButton> saveOrUpdateViewButtons(Set<ViewButton> viewButtons){
		StringBuilder errorString = new StringBuilder();
		for (ViewButton viewButton : viewButtons) {
			try {
				saveOrUpdateViewButton(viewButton);
			} catch (ValidateRuntimeException ex) {
				errorString.append(ex.getMessage() + "\n");
			}
		}
		if (errorString.length() > 0) {
			throw new ValidateRuntimeException(errorString.toString());
		}
		return viewButtons;
	}

	public ViewButton updateViewButton(ViewButton viewButton) {
		return (ViewButton) super.updateObject(viewButton);
	}	
	

}
